<template>
    <!-- 批量加班 -->
    <div>
        <Dialog
                ref="d1"
                dialogCls="mydlgg"
                headerCls="mydlgg-head"
                footerCls="mydlgg-foot"
                :dialogStyle="{ width: '1160px', marginTop: '50px' }"
                :modal="true"
                borderType="thin"
                @close="close"
        >
            <div slot="header">
                <span class="headerIcon newlyAdded"></span>
                <span class="titleStyle">批量加班</span>
            </div>

            <div class="insidePadding">
                <div class="upContent" style="height:498px">
                    <!-- 左侧树容器 -->
                    <div class="borderGray leftCont" style="width:240px">
                        <sidebar-dept
                                ref="gridModel"
                                :treeId="'gridModel'"
                                :treeHeight="treeHeight"
                                :userIds="userIds"
                        />
                    </div>

                    <div style="flex:1;margin:0 0 0 10px">
                        <fieldset class="fieldsetStyle">
                            <fieldset class="fieldsetStyle" style="height:180px">
                                <legend>
                                    <b style="color:#293569">选择日期范围</b>
                                </legend>

                                <div class="fleft">
                                    <Label for="DateBox1">加班日期</Label>
                                    <DateBox
                                            inputId="DateBox1"
                                            format="yyyy-MM-dd"
                                            v-model="dateScope.otDate"
                                            @valueChange="selectionChangeOverTime"
                                            :disabled="isCanSelect"
                                            :editable="false"
                                            :validator="otDateValidator"
                                    />
                                </div>
                                <div class="fenGeXian"></div>
                                <div
                                        style="line-height: 20px;display: flex;align-items:center;"
                                >
                                    <label class="textbox-label" for="sj">手动设置</label>
                                    <RadioButton
                                            inputId="sj"
                                            class="rs_15"
                                            name="groupTime"
                                            value="1"
                                            v-model="timeSelectPattern"
                                    ></RadioButton>
                                    <label class="textbox-label" for="banCi">按班次设置</label>
                                    <RadioButton
                                            inputId="banCi"
                                            class="rs_15"
                                            name="groupTime"
                                            value="2"
                                            v-model="timeSelectPattern"
                                    ></RadioButton>
                                </div>
                                <div class="fenGeXian"></div>
                                <div style="width: 100%" v-show="banciSelectFlag">
                                    <Label>选择班次</Label>
                                    <ComboBox
                                            :disabled="timeFlag"
                                            ref="selectBanCi"
                                            valueField="id"
                                            textField="name"
                                            v-model="dateScope.banCiType"
                                            :virtualScroll="true"
                                            :data="dateScope.banCiTypeData"
                                            :panelStyle="panelStyle3"
                                            @selectionChange="selectionChangeBanCi"
                                    ></ComboBox>
                                </div>
                                <div class="fleft" v-show="timeFlag">
                                    <Label for="DateBox2">开始时间</Label>
                                    <DateBox
                                            :disabled="banciSelectFlag"
                                            inputId="DateBox2"
                                            format="yyyy-MM-dd"
                                            v-model="dateScope.startDate"
                                            :validator="validator"
                                            :editable="false"
                                    />
                                </div>
                                <div class="fleft" v-show="timeFlag">
                                    <Label></Label>
                                    <NumberBox
                                            :disabled="banciSelectFlag"
                                            :min="0"
                                            :max="23"
                                            :spinners="true"
                                            style="width:60px"
                                            v-model="dateScope.beginHour"
                                            :prefix="dateScope.beginHour < 10 ? '0' : ''"
                                    ></NumberBox>
                                    <span class="inputStyle">时</span>
                                    <ComboBox
                                            :disabled="banciSelectFlag"
                                            valueField="id"
                                            textField="name"
                                            :style="{ width: '60px' }"
                                            v-model="dateScope.beginMinute"
                                            :virtualScroll="true"
                                            :data="[
                      { id: '00', name: '00' },
                      { id: '15', name: '15' },
                      { id: '30', name: '30' },
                      { id: '45', name: '45' }
                    ]"
                                            :panelStyle="panelStyle3"
                                    ></ComboBox>
                                    <span class="inputStyle">分</span>
                                    <!-- <NumberBox
                                                                          :min="0"
                                                                          :max="59"
                                                                          :spinners="true"
                                                                          style="width:60px"
                                                                          v-model="dateScope.beginMinute"
                                                                          :prefix="dateScope.beginMinute < 10 ? '0' : ''"
                                                                        ></NumberBox> -->
                                </div>
                                <div class="fleft" v-show="timeFlag">
                                    <Label for="DateBox3">结束时间</Label>
                                    <DateBox
                                            :disabled="banciSelectFlag"
                                            :readonly="false"
                                            inputId="DateBox3"
                                            format="yyyy-MM-dd"
                                            v-model="dateScope.endDate"
                                            :validator="validator"
                                            :editable="false"
                                    />
                                </div>
                                <div class="fleft" v-show="timeFlag">
                                    <Label></Label>
                                    <NumberBox
                                            :disabled="banciSelectFlag"
                                            :min="0"
                                            :max="23"
                                            :spinners="true"
                                            style="width:60px"
                                            v-model="dateScope.endHour"
                                            :prefix="dateScope.endHour < 10 ? '0' : ''"
                                    ></NumberBox>
                                    <span class="inputStyle">时</span>
                                    <ComboBox
                                            :disabled="banciSelectFlag"
                                            valueField="id"
                                            textField="name"
                                            :style="{ width: '60px' }"
                                            v-model="dateScope.endMinute"
                                            :virtualScroll="true"
                                            :data="[
                      { id: '00', name: '00' },
                      { id: '15', name: '15' },
                      { id: '30', name: '30' },
                      { id: '45', name: '45' }
                    ]"
                                            :panelStyle="panelStyle3"
                                    ></ComboBox>
                                    <span class="inputStyle">分</span>
                                    <!-- <NumberBox
                                                                          :min="0"
                                                                          :max="59"
                                                                          :spinners="true"
                                                                          style="width:60px"
                                                                          v-model="dateScope.endMinute"
                                                                          :prefix="dateScope.endMinute < 10 ? '0' : ''"
                                                                        ></NumberBox> -->
                                </div>
                            </fieldset>
                            <fieldset
                                    class="fieldsetStyle"
                                    style="height:55px;margin:10px 0px;"
                            >
                                <legend>
                                    <b style="color:#293569">选择审批人</b>
                                </legend>
                                <select-approver ref="appr"></select-approver>
                            </fieldset>
                            <fieldset
                                    class="fieldsetStyle"
                                    style="height:115px;margin-bottom:10px;"
                            >
                                <legend>
                                    <b style="color:red">*</b>
                                    <b style="color:#293569">事由</b>
                                </legend>
                                <!-- fieldset、legend如果需要带边框加标题的容器这俩标签必须保留 -->
                                <TextBox
                                        :multiline="true"
                                        v-model="dateScope.reason"
                                        style="width:100%;height:85px"
                                        placeholder="请填写加班事由（必填）"
                                ></TextBox>
                            </fieldset>
                            <fieldset class="fieldsetStyle" style="height:104px;">
                                <legend>
                                    <b style="color:#293569">上传附件</b>
                                </legend>
                                <upload-file ref="upload1"/>
                                <upload-file ref="upload2"/>
                                <upload-file ref="upload3"/>
                            </fieldset>
                        </fieldset>
                    </div>

                    <div
                            style="width:80px;display: flex; justify-content:center; align-items:center;flex-direction:column"
                    >
                        <LinkButton btnCls="c1" class="rightWard" @click="toRight"
                        >》》
                        </LinkButton>
                        <LinkButton btnCls="c1" class="leftWard" @click="toLeft"
                        >《《
                        </LinkButton>
                    </div>

                    <div style="width: 294px;height: 100%;">
                        <!-- 右上角表格 -->
                        <div class="borderGray" style="height:100%;width: 100%">
                            <DataGrid
                                    :data="xz.peopleData"
                                    style="height:100%;width: 100%"
                                    :pagination="true"
                                    :pageSize="100"
                                    :total="xz.peopleTotal"
                            >
                                <GridColumn field="ck" :width="40" align="center">
                                    <!-- <template slot="header" slot-scope="scope"> -->
                                    <template slot="header" slot-scope="scope">
                                        <CheckBox
                                                class="cbs_15"
                                                v-model="xz.allChecked"
                                                @checkedChange="onAllCheckedChange($event)"
                                        ></CheckBox>
                                    </template>
                                    <template slot="body" slot-scope="scope">
                                        <CheckBox
                                                class="cbs_15"
                                                v-model="scope.row.selected"
                                                @checkedChange="onCheckedChange($event)"
                                        ></CheckBox>
                                    </template>
                                </GridColumn>
                                <GridColumn
                                        :width="50"
                                        field="userNo"
                                        title="工号"
                                        align="center"
                                ></GridColumn>
                                <GridColumn
                                        :width="50"
                                        field="userName"
                                        title="姓名"
                                        align="center"
                                ></GridColumn>
                                <GridColumn
                                        :width="160"
                                        field="deptName"
                                        title="部门"
                                        align="center"
                                ></GridColumn>
                                <GridColumn
                                        :width="140"
                                        field="startDateTime"
                                        title="开始时间"
                                        align="center"
                                ></GridColumn>
                                <GridColumn
                                        :width="140"
                                        field="endDateTime"
                                        title="结束时间"
                                        align="center"
                                ></GridColumn>
                                <GridColumn
                                        :width="60"
                                        field="timeDuration"
                                        title="加班时长"
                                        align="center"
                                ></GridColumn>
                                <GridColumn
                                        :width="160"
                                        field="reason"
                                        title="加班事由"
                                        align="center"
                                ></GridColumn>
                            </DataGrid>
                        </div>
                    </div>
                </div>
            </div>

            <div slot="footer" style="border:none">
                <div class="footerDiv">
                    <!-- footer、footerDiv这两个div必须保留 -->
                    <LinkButton @click="submitOverTime" class="saveBtn">保存</LinkButton>
                    <span style="margin:0px 10px;"/>
                    <LinkButton @click="close" class="cancelBtn">返回</LinkButton>
                </div>
            </div>
        </Dialog>

        <!--加班错误详情-->
        <Dialog
                ref="errorXq"
                dialogCls="mydlgg"
                headerCls="mydlgg-head"
                footerCls="mydlgg-foot"
                :dialogStyle="{ width: '720px', marginTop: '50px' }"
                :modal="true"
                borderType="thin"
        >
            <div slot="header">
                <span class="headerIcon newlyAdded"></span>
                <span class="titleStyle">加班错误详情</span>
            </div>
            <div class="insidePadding">
                <!-- 这个div必须保留 -->
                <fieldset class="fieldsetStyle">
                    <!-- 表格容器   -->
                    <div style="height: 450px">
                        <ag-grid-vue
                                style="width: 100%; height: 100%;"
                                class="ag-theme-balham"
                                :rowData="err.xqRowData"
                                :columnDefs="err.xqColumnDefs"
                        ></ag-grid-vue>
                    </div>
                </fieldset>
            </div>
        </Dialog>
    </div>
</template>

<script>
    import userApi from "@/api/user";
    import itemApi from "@/api/sys/item";
    import scheduleApi from "@/api/schedule/schedule";
    import overTimeApi from "@/api/overTime/overTime";
    import timeIntervalApi from "@/api/timeInterval/timeInterval";
    import sidebarDept from "@/components/dept/sidebarDept";
    // import {tableBoxHeight} from "@/api/communal";
    import {AgGridVue} from "ag-grid-vue";
    import dateUtil from "@/utils/dateUtils";
    import moment from "moment";
    import UploadFile from "@/components/uploadFile";
    import selectApprover from "@/components/selectApprover";

    export default {
        props: {
            parentSearch: Function,
            userIds: String,
            selectedRowsdatas: {
                type: Array,
                default: () => []
            } //主页面选择的人员集合
        },
        components: {
            sidebarDept,
            AgGridVue,
            UploadFile,
            selectApprover
        },
        name: "",
        data() {
            return {
                showDialog: false,
                panelStyle2: {
                    height: "auto"
                },
                panelStyle: {
                    height: "100px",
                    borderWidth: "1px",
                    borderColor: "#ccc",
                    borderStyle: "solid"
                },
                panelStyle3: {
                    height: "auto",
                    maxHeight: "150px",
                    borderWidth: "1px",
                    borderColor: "#ccc",
                    borderStyle: "solid"
                },
                treeHeight: "height:226px",
                xz: {
                    rowHeight: 30,
                    /*加班人员表格*/
                    peopleData: [],
                    peopleTotal: 0,
                    /*复选框*/
                    allChecked: false,
                    rowClicked: false
                },
                banCiId: {
                    id: null
                },
                dateScope: {
                    otDate: new Date(),
                    startDate: new Date(),
                    endDate: new Date(),
                    beginHour: 0,
                    beginMinute: 0,
                    endHour: 0,
                    endMinute: 0,
                    //加班单是否为调休
                    isLeave: 0,
                    overTimeType: null,
                    overTimeTypeData: [],
                    isRepast: false,
                    isRepastDisabled: false,
                    //按班次录入
                    banCiType: null,
                    banCiTypeData: [],

                    //加班事由
                    reason: "",

                    //按时段录入
                    timeInterval: [],
                    //上传的文件名数组
                    uploadFileNames: []

                    //按时间录入
                },
                err: {
                    xqRowData: [],
                    xqColumnDefs: [
                        {headerName: "工号", field: "userNo", width: 100},
                        {headerName: "姓名", field: "userName", width: 100},
                        {headerName: "部门", field: "deptName", width: 200},
                        {headerName: "错误信息", field: "errorMsg", width: 500}
                    ]
                },
                /*时间选择收集*/
                timeSelectPattern: "1",
                timeFlag: true,
                banciSelectFlag: false,
                /*加班日期组件是否禁止操作*/
                isCanSelect: false
            };
        },
        watch: {
            timeSelectPattern(val, oldVal) {
                this.timeSelectPatternFun(null);
            }
        },
        mounted() {
            // tableBoxHeight();
            this.$refs.d1.close();
            this.$refs.errorXq.close();
            // 普通排班类型
            scheduleApi.getSchedulePuTong().then(res => {
                if (res.code == 200) {
                    this.dateScope.banCiTypeData = res.result;
                    //班次类型赋值
                    //this.dateScope.banCiType = res.result[0].id;
                } else {
                    this.$messager.alert({
                        title: "操作提示",
                        icon: "error",
                        msg: res.message
                    });
                }
            });
        },
        computed: {
            checkedRows() {
                return this.xz.peopleData.filter(row => row.selected);
            }
        },
        methods: {
            open() {
                // this.$refs.d1.open();
                // this.showDialog = true;
                //this.clearData();
                this.$refs.d1.open();
            },
            close() {
                this.clearData();
                this.$refs.d1.close();
                // console.log("关闭窗体");
                // this.showDialog = false;
            },
            //保存加班，提交
            submitOverTime() {
                if (
                    this.xz.peopleData == [] ||
                    this.xz.peopleData.length == 0 ||
                    this.xz.peopleData == null
                ) {
                    this.$messager.alert({
                        title: "操作提示",
                        icon: "warning",
                        msg: "请将用户添加到右侧表格中!"
                    });
                    return;
                }
                let otDate = moment(this.dateScope.otDate).format("YYYY-MM-DD");
                if (otDate == "" || otDate == "Invalid date" || otDate == null) {
                    this.$messager.alert({
                        title: "操作提示",
                        icon: "warning",
                        msg: "请选择加班日期!"
                    });
                    return;
                }
                if (this.$refs.appr.workshopApprover == "") {
                    this.$messager.alert({
                        title: "操作提示",
                        icon: "warning",
                        msg: "请选择一级审批人!"
                    });
                    return;
                }
                if (this.$refs.appr.labourUnionApprover == "") {
                    this.$messager.alert({
                        title: "操作提示",
                        icon: "warning",
                        msg: "请选择二级审批人!"
                    });
                    return;
                }

                // 封装参数：文件名数组
                this.getUploadFileNames();

                let param = {
                    //加班日期
                    otDate: otDate,
                    //加班人员信息 JSON数组
                    otDetailDtoList: this.xz.peopleData,
                    //上传文件的路径 字符串数组
                    uploadFileNames: this.dateScope.uploadFileNames,
                    //一级审批人
                    workshopApprover: this.$refs.appr.workshopApprover,
                    //二级审批人
                    labourUnionApprover: this.$refs.appr.labourUnionApprover,
                    applyType: "2"
                };
                /*console.log(param)
                return;
*/
                this.$loading("请稍等...");
                // 添加加班
                overTimeApi.addOverTimeOrder(param).then(res => {
                    this.$loading.close();
                    if (res.code == 200) {
                        this.parentSearch();
                        this.close();
                        this.$messager.alert({
                            title: "系统提示",
                            icon: "success",
                            msg: "保存成功！"
                        });
                    } else {
                        if (res.result == null || res.result.length == 0) {
                            this.$messager.alert({
                                title: "系统提示",
                                icon: "error",
                                msg: res.message
                            });
                        } else {
                            let pNum = res.result.length;
                            if (this.xz.peopleData.length > pNum) {
                                this.$messager.confirm({
                                    title: "系统提示",
                                    msg: "保存成功！,部分人失败,点击确定查看详情。",
                                    result: r => {
                                        if (r) {
                                            this.parentSearch();
                                            this.close();
                                            this.err.xqRowData = res.result;
                                            this.$refs.errorXq.open();
                                        }
                                    }
                                });
                            } else {
                                this.$messager.confirm({
                                    title: "系统提示",
                                    msg: "保存失败！,点击确定查看详情。",
                                    result: r => {
                                        if (r) {
                                            this.err.xqRowData = res.result;
                                            this.$refs.errorXq.open();
                                        }
                                    }
                                });
                            }
                        }
                    }
                });
            },
            toRight() {
                let tab = this.$refs.gridModel.selectTab;
                let deptIds = null;
                let userIds = null;
                //判断tab的选择是部门还是人员
                if (tab == 1) {
                    deptIds = this.$refs.gridModel.getSelectDeptIds();
                    if (deptIds == null || deptIds == "") {
                        this.$messager.alert({
                            title: "系统提示",
                            icon: "warning",
                            msg: "请勾选要加班的部门!"
                        });
                        return;
                    }
                } else {
                    userIds = this.$refs.gridModel.getSelectUserIds();
                    if (userIds == null || userIds == "") {
                        this.$messager.alert({
                            title: "系统提示",
                            icon: "warning",
                            msg: "请勾选要加班的人员!"
                        });
                        return;
                    }
                }

                let startDateTime = null;
                let endDateTime = null;
                let otBegin = null;
                let otEnd = null;
                if (this.timeSelectPattern == "2") {
                    if (
                        this.dateScope.banCiType == "" ||
                        this.dateScope.banCiType == null
                    ) {
                        this.$messager.alert({
                            title: "操作提示",
                            icon: "warning",
                            msg: "请选择班次!"
                        });
                        return;
                    }
                } else {
                    if (
                        this.dateScope.beginHour == null ||
                        this.dateScope.beginMinute == null ||
                        this.dateScope.startDate == null
                    ) {
                        this.$messager.alert({
                            title: "操作提示",
                            icon: "warning",
                            msg: "请输入完整的开始时间!"
                        });
                        return;
                    }

                    if (
                        this.dateScope.endHour == null ||
                        this.dateScope.endMinute == null ||
                        this.dateScope.endDate == null
                    ) {
                        this.$messager.alert({
                            title: "操作提示",
                            icon: "warning",
                            msg: "请输入完整的结束时间!"
                        });
                        return;
                    }
                    startDateTime = moment(this.dateScope.startDate)
                        .hour(this.dateScope.beginHour)
                        .minute(this.dateScope.beginMinute);
                    endDateTime = moment(this.dateScope.endDate)
                        .hour(this.dateScope.endHour)
                        .minute(this.dateScope.endMinute);
                    otBegin = startDateTime.diff(
                        moment(moment(this.dateScope.otDate).format("YYYY-MM-DD")),
                        "minute"
                    );
                    otEnd = endDateTime.diff(
                        moment(moment(this.dateScope.otDate).format("YYYY-MM-DD")),
                        "minute"
                    );
                    if (otEnd - otBegin < 120) {
                        this.$messager.alert({
                            title: "操作提示",
                            icon: "warning",
                            msg: "加班结束时间必须大于加班开始时间,并且最小间隔为2小时！"
                        });
                        return;
                    }
                }
                /*加班事由与人员关联而非整个单子*/
                if (this.dateScope.reason == null || this.dateScope.reason == "") {
                    this.$messager.alert({
                        title: "系统提示",
                        icon: "warning",
                        msg: "加班事由必填!"
                    });
                    return;
                }
                //整理请求的数据
                let param = {
                    deptIds: deptIds,
                    userIds: userIds,
                    actionDate: moment(this.dateScope.otDate).format("YYYY-MM-DD")
                };
                this.$loading("请稍等...");
                userApi.getUserCalendarInfoList(param).then(res => {
                    this.$loading.close();
                    if (res.code == "200") {
                        let selectUser = res.result.map(res => {
                            return {
                                userNo: res.userNo,
                                userName: res.userName,
                                userSerial: res.userSerial,
                                deptName: res.deptName,
                                deptSerial: res.deptSerial,
                                isRest: res.isRest
                            };
                        });
                        //1人员存在，是否覆盖
                        let resetUser = selectUser.filter(a => {
                            //已存在的
                            return this.xz.peopleData.find(b => {
                                return a.userSerial == b.userSerial;
                            });
                        });
                        if (resetUser != null && resetUser.length != 0) {
                            this.$messager.confirm({
                                title: "请确认操作",
                                msg: "人员存在人员列表中，是否覆盖？",
                                result: r => {
                                    if (r) {
                                        resetUser.forEach(a => {
                                            this.xz.peopleData.forEach(b => {
                                                if (a.userSerial == b.userSerial) {
                                                    //根据手动、班次取值
                                                    if (this.timeSelectPattern == "1") {
                                                        b.otBegin = otBegin;
                                                        b.otEnd = otEnd;
                                                        b.reason = this.dateScope.reason;
                                                        b.startDateTime = moment(startDateTime).format(
                                                            "YYYY-MM-DD HH:mm"
                                                        );
                                                        b.endDateTime = moment(endDateTime).format(
                                                            "YYYY-MM-DD HH:mm"
                                                        );
                                                        b.timeDuration = dateUtil.toHourMinute(
                                                            otEnd - otBegin
                                                        );
                                                        b.repastTime = 0
                                                    } else {
                                                        //根据当前日期是否是休息日，来确定时间取值
                                                        let otStartTime = null;
                                                        let otEndTime = null;
                                                        let otBegin = null;
                                                        let otEnd = null;
                                                        if (a.isRest == 1) {
                                                            otStartTime = moment(this.dateScope.otDate)
                                                                .startOf("day")
                                                                .add(
                                                                    this.dateScope.timeInterval.zzSbsj,
                                                                    "minute"
                                                                );
                                                            otEndTime = moment(this.dateScope.otDate)
                                                                .startOf("day")
                                                                .add(
                                                                    this.dateScope.timeInterval.zwXbsj,
                                                                    "minute"
                                                                );
                                                            otBegin = this.dateScope.timeInterval.zzSbsj;
                                                            otEnd = this.dateScope.timeInterval.zwXbsj;
                                                        } else {
                                                            otStartTime = moment(this.dateScope.otDate)
                                                                .startOf("day")
                                                                .add(this.dateScope.timeInterval.sbsj, "minute");
                                                            otEndTime = moment(this.dateScope.otDate)
                                                                .startOf("day")
                                                                .add(this.dateScope.timeInterval.xbsj, "minute");
                                                            otBegin = this.dateScope.timeInterval.sbsj;
                                                            otEnd = this.dateScope.timeInterval.xbsj;
                                                        }
                                                        //更新参数
                                                        b.otBegin = otBegin;
                                                        b.otEnd = otEnd;
                                                        b.reason = this.dateScope.reason;
                                                        b.startDateTime = moment(otStartTime).format(
                                                            "YYYY-MM-DD HH:mm"
                                                        );
                                                        b.endDateTime = moment(otEndTime).format(
                                                            "YYYY-MM-DD HH:mm"
                                                        );
                                                        b.timeDuration = dateUtil.toHourMinute(
                                                            otEnd - otBegin-this.dateScope.timeInterval.repastTime
                                                        );
                                                        b.repastTime = this.dateScope.timeInterval.repastTime
                                                        //班次ID要带上
                                                        b.shiftId = this.dateScope.timeInterval.parent;
                                                    }
                                                }
                                            });
                                        });
                                    } else {
                                        //console.log("不覆盖");
                                    }
                                }
                            });
                        }
                        let newUser = selectUser.filter(a => {
                            //没有找到的就是需要添加的
                            return !this.xz.peopleData.find(b => {
                                return a.userSerial == b.userSerial;
                            });
                        });

                        //2新增人员
                        if (newUser != null && newUser.length != 0) {
                            //根据手动、班次取值
                            if (this.timeSelectPattern == "1") {
                                newUser.forEach(a => {
                                    a.otBegin = otBegin;
                                    a.otEnd = otEnd;
                                    a.reason = this.dateScope.reason;
                                    a.startDateTime = moment(startDateTime).format(
                                        "YYYY-MM-DD HH:mm"
                                    );
                                    a.endDateTime = moment(endDateTime).format("YYYY-MM-DD HH:mm");
                                    a.timeDuration = dateUtil.toHourMinute(otEnd - otBegin);
                                    a.repastTime = 0
                                });
                            } else {
                                //根据当前日期是否是休息日，来确定时间取值
                                let otStartTime = null;
                                let otEndTime = null;
                                let otBegin = null;
                                let otEnd = null;
                                newUser.forEach(a => {
                                    if (a.isRest == 1) {
                                        otStartTime = moment(this.dateScope.otDate)
                                            .startOf("day")
                                            .add(this.dateScope.timeInterval.zzSbsj, "minute");
                                        otEndTime = moment(this.dateScope.otDate)
                                            .startOf("day")
                                            .add(this.dateScope.timeInterval.zwXbsj, "minute");
                                        otBegin = this.dateScope.timeInterval.zzSbsj;
                                        otEnd = this.dateScope.timeInterval.zwXbsj;
                                    } else {
                                        otStartTime = moment(this.dateScope.otDate)
                                            .startOf("day")
                                            .add(this.dateScope.timeInterval.sbsj, "minute");
                                        otEndTime = moment(this.dateScope.otDate)
                                            .startOf("day")
                                            .add(this.dateScope.timeInterval.xbsj, "minute");
                                        otBegin = this.dateScope.timeInterval.sbsj;
                                        otEnd = this.dateScope.timeInterval.xbsj;
                                    }
                                    a.otBegin = otBegin;
                                    a.otEnd = otEnd;
                                    a.reason = this.dateScope.reason;
                                    a.startDateTime = moment(otStartTime).format(
                                        "YYYY-MM-DD HH:mm"
                                    );
                                    a.endDateTime = moment(otEndTime).format("YYYY-MM-DD HH:mm");
                                    a.timeDuration =
                                        dateUtil.toHourMinute(otEnd - otBegin-this.dateScope.timeInterval.repastTime);
                                    a.repastTime = this.dateScope.timeInterval.repastTime
                                    //班次ID要带上
                                    a.shiftId = this.dateScope.timeInterval.parent;
                                });
                            }
                            this.xz.allChecked = false;
                            this.xz.peopleData.push(...newUser);
                            this.xz.peopleTotal = this.xz.peopleData.length;
                        }

                        this.isCanSelectDate();

                        //console.log(this.xz.peopleData)
                    } else {
                        this.$messager.alert({
                            title: "异常错误",
                            icon: "error",
                            msg: "加载列表失败!"
                        });
                    }
                });
            },
            toLeft() {
                if (this.xz.allChecked) {
                    this.xz.peopleData = [];
                    this.xz.allChecked = false;
                } else {
                    this.xz.peopleData = this.xz.peopleData.filter(
                        row => row.selected != true
                    );
                }
                this.xz.peopleTotal = this.xz.peopleData.length;
                this.isCanSelectDate();
            },
            /*是否禁止加班日期选择*/
            isCanSelectDate() {
                this.isCanSelect = this.xz.peopleData.length == 0 ? false : true;
            },
            //录入成功 清除数据
            clearData() {
                this.$refs.gridModel.setTabs(0);
                this.xz.allChecked = false;
                this.xz.rowClicked = false;
                this.xz.peopleData = [];
                this.xz.peopleTotal = 0;
                this.dateScope.otDate = new Date();
                this.dateScope.isLeave = 0;
                this.dateScope.isRepast = false;
                this.dateScope.startDate = new Date();
                this.dateScope.endDate = new Date();
                this.dateScope.beginHour = 0;
                this.dateScope.beginMinute = 0;
                this.dateScope.endHour = 0;
                this.dateScope.endMinute = 0;
                this.dateScope.reason = "";
                this.dateScope.banCiType = null; //this.dateScope.banCiTypeData[0].id;
                this.dateScope.overTimeType = null; //this.dateScope.overTimeTypeData[0].id;
                this.isCanSelectDate();
            },
            onAllCheckedChange(checked) {
                if (this.xz.rowClicked) {
                    return;
                }
                this.xz.peopleData = this.xz.peopleData.map(row => {
                    return Object.assign({}, row, {
                        selected: checked
                    });
                });
            },
            onCheckedChange(checked) {
                this.xz.allChecked =
                    this.checkedRows.length === this.xz.peopleData.length;
                this.xz.rowClicked = true;
                this.$nextTick(() => (this.xz.rowClicked = false));
            },
            //选择上传文件
            onFileSelect() {
            },
            // 选择加班日期
            selectionChangeOverTime() {
                this.timeSelectPatternFun(true);
            },
            //选择班次 加载班次时段
            selectionChangeBanCi(event) {
                if (event == null) {
                    return false;
                }
                this.banCiId.id = event.id;
                // console.log(this.banCiId.id);
                timeIntervalApi
                    .getTimeIntervalListByParent({
                        parent: this.banCiId.id
                    })
                    .then(res => {
                        //处理班次时段
                        this.dateScope.timeInterval = res.result[0];
                    });
            },
            //整理上传文件名集合
            getUploadFileNames() {
                this.dateScope.uploadFileNames = [];
                let upload1 = this.$refs.upload1.getUploadFileName();
                this.addFileNames(upload1);
                let upload2 = this.$refs.upload2.getUploadFileName();
                this.addFileNames(upload2);
                let upload3 = this.$refs.upload3.getUploadFileName();
                this.addFileNames(upload3);
            },
            //添加上传文件名到集合
            addFileNames(name) {
                if (name != null) {
                    this.dateScope.uploadFileNames.push(name);
                }
            },
            validator(date) {
                {
                    if (
                        date >=
                        moment(this.dateScope.otDate)
                            .startOf("day")
                            .subtract(1, "d") &&
                        date <=
                        moment(this.dateScope.otDate)
                            .startOf("day")
                            .add(1, "d")
                    ) {
                        return true;
                    }
                    return false;
                }
            },
            otDateValidator(date) {
                {
                    if (
                        date >=
                        moment(new Date())
                            .startOf("day")
                            .subtract(7, "d")
                    ) {
                        return true;
                    }
                    return false;
                }
            },
            /*切换取时间的方式*/
            timeSelectPatternFun(isSelectDate) {
                if (isSelectDate != null) {
                    this.dateScope.banCiType = null;
                    this.dateScope.startDate = this.dateScope.otDate;
                    this.dateScope.beginHour = 0;
                    this.dateScope.beginMinute = 0;
                    this.dateScope.endDate = this.dateScope.otDate;
                    this.dateScope.endHour = 0;
                    this.dateScope.endMinute = 0;
                }
                {
                    if (this.timeSelectPattern == "1") {
                        //手动设置，即将选择的班次初始化，并禁用，日期选择放开
                        this.timeFlag = true;
                        this.banciSelectFlag = false;
                        //初始化
                        this.dateScope.banCiType = null;
                        this.dateScope.startDate = this.dateScope.otDate;
                        this.dateScope.beginHour = 0;
                        this.dateScope.beginMinute = 0;
                        this.dateScope.endDate = this.dateScope.otDate;
                        this.dateScope.endHour = 0;
                        this.dateScope.endMinute = 0;
                    } else {
                        //根据班次，即启用下拉框，并禁用日期选择。
                        this.timeFlag = false;
                        this.banciSelectFlag = true;
                        //初始化
                        this.dateScope.startDate = this.dateScope.otDate;
                        this.dateScope.beginHour = 0;
                        this.dateScope.beginMinute = 0;
                        this.dateScope.endDate = this.dateScope.otDate;
                        this.dateScope.endHour = 0;
                        this.dateScope.endMinute = 0;
                    }
                }
            }
        }
    };
</script>

<style scoped></style>
